package com.foxzzz.array;

/**
 * @Author wujie
 * @Class Solution303
 * @Description
 * @Date 2021/3/1 16:01
 */
public class Solution303 {

    class NumArray {

        private int[] nums = null;

        public NumArray(int[] nums) {
            this.nums = nums;
        }

        public int sumRange(int i, int j) {
            int sum = 0;
            for (int i1 = i; i1 <= j; i1++) {
                sum += nums[i1];
            }
            return sum;
        }
    }

    class NumArray1 {
        int[] sums;

        public NumArray1(int[] nums) {
            int n = nums.length;
            sums = new int[n + 1];
            for (int i = 0; i < n; i++) {
                sums[i + 1] = sums[i] + nums[i];
            }
        }

        public int sumRange(int i, int j) {
            return sums[j + 1] - sums[i];
        }
    }

}
